package org.openfdtd.core3d;

import java.util.ArrayList;

/**
 *
 * @author Dorian C. Langbeck
 */
public class Edge extends Object {
    private ArrayList<Surface> parents = new ArrayList<Surface>();
    private Vertex[] vertexes;
    private double[] coordinates;

    public Edge(Vertex v1, Vertex v2) {
        vertexes = new Vertex[] {v1, v2};
        updateCoordinates();
        v1.childOf(this);
        v2.childOf(this);
    }

    private void updateCoordinates() {
        coordinates = new double[6];
        System.arraycopy(vertexes[0].getCoordinate(), 0, coordinates, 0, 3);
        System.arraycopy(vertexes[1].getCoordinate(), 0, coordinates, 3, 3);
    }

    public Vertex[] getVertexes() {
        return vertexes;
    }

    public double[] getCoordinates() {
        return coordinates;
    }

    public boolean samePoints(Edge e) {
        Vertex[] vp = e.getVertexes();
        
        return (vertexes[0].equals(vp[0]) && vertexes[1].equals(vp[1])) ||
               (vertexes[1].equals(vp[0]) && vertexes[0].equals(vp[1]));
    }

    public void childOf(Surface parent) {
        parents.add(parent);
    }

    public boolean isChildOf(Surface parent) {
        return parents.contains(parent);
    }

    public Surface[] getParents() {
        return (Surface[]) parents.toArray();
    }

    public boolean removeParent(Surface parent) {
        return parents.remove(parent);
    }
}
